package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class AdministrativeServiceImpl implements AdministrativeService{

    @Autowired
    private DtsRegionMapper regionMapper;

    @Override
    public IPage<DtsRegion> queryRegionPage(String name, String code, Integer page, Integer limit) {
        //1创建分页对象
        IPage<DtsRegion> ipage =new Page<>(page,limit);
        //2封装查询对象
        QueryWrapper<DtsRegion> queryWrapper = new QueryWrapper<>();

        //3判断查询条件不为空拼接查询条件
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);

        }
        if (!StringUtils.isEmpty(code)){
            queryWrapper.eq("code",code);

        }

        //4查询并返回结果
        IPage<DtsRegion> resultPage = regionMapper.selectPage(ipage,queryWrapper);


        return resultPage;
    }
}
